<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Auth extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->disable_layout();
    }

    /**
     * Default function
     */
    public function index()
    {
        
    }
    public function login(){
        $this->load->library('form_validation');
        $this->disable_view();
        $post = $this->input->post(null);
        if(empty($post['username']) || empty($post['password'])){
            _set_error_message('Please provide both email and password');
            
        }else
        {
            if($this->tank_auth->login($post['username'],$post['password'],false,true,false)){
                if($this->tank_auth->is_admin()){
                //_set_success_message($this->session->userdata['roles']);
                session_start();
                $_SESSION['auth']=1;
                
                redirect('administrator/shop');
                }
                else
                _set_error_message('Your account cannot access this page...');
                
            }
                
            else{
                _set_error_message('Your username and password is incorrect. Please try again...');
                
            }
        }
            redirect('administrator/auth');   
    }
    public function logout(){
        $this->disable_view();
        $this->tank_auth->logout();
        redirect('administrator'); 
    }
    

}